import { createWebHistory, createRouter } from 'vue-router'

const routes = [{
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('./Base/404.vue'),
    hidden: true
}]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

router.beforeEach((to, from, next) => {
    // 检查是否从/html重定向
    if (from.path === '/index.html') {
        // 构造新的路径，包括查询参数
        const newPath = `/?${new URLSearchParams(from.query).toString()}`;
        // 重定向到新的路径
        next(newPath);
    } else {
        // 对于其他情况，正常继续
        next();
    }
});

const addRouters = function (routers) {
    for (let i = 0; i < routers.length; i++) {
        const element = routers[i];
        router.addRoute(element);
    }
}

export { router, addRouters }